﻿namespace Serializator.Composits
{
    using System;
    using Serializator.JSONObjects;

    public class Contact : IAssignable
    {
        #region Constructors

        public Contact()
            : this(string.Empty, string.Empty)
        {
        }

        public Contact(Contact c)
            : this(c.PhoneNumber, c.Email)
        {
        }

        public Contact(string phoneNumber, string email)
        {
            PhoneNumber = phoneNumber;
            Email = email;
        }

        #endregion Constructors

        #region IAssignable implementation

        public void AssignTo(object obj)
        {
            if (obj == null)
                throw new ArgumentNullException();

            if (obj is Contact)
            {
                Contact c = obj as Contact;
                c.Email = Email;
                c.PhoneNumber = PhoneNumber;

                return;
            }

            if (obj is JSONObject)
            {
                JSONObject result = obj as JSONObject;
                JSONSerializer ser = new JSONSerializer();
                result.EncodedStreamList = ser.Serialize(this).EncodedStreamList;

                return;
            }

            throw new NotSupportedException();
        }

        #endregion

        #region Properties

        public string PhoneNumber { get; set; }
        public string Email { get; set; }

        #endregion Properties

    }
}
